package com.hongxun.design.utils;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

/**
 * Created by zerdoor_pc on 2016/6/2.
 */
public class InputUtil {
    /**关闭输入法**/
    public static void closeInput(Activity context) {
        try {
            InputMethodManager im = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
            im.hideSoftInputFromWindow(context.getCurrentFocus().getApplicationWindowToken(), 0);
        } catch (NullPointerException e) {

        }
    }

    /**打开输入法**/
    public static void openInput(Activity context,View view) {
        try {
//            InputMethodManager im = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
            InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(view, 0);
            imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
        } catch (NullPointerException e) {

        }
    }
}
